#include "agency.h"
#include <sstream>


template<typename T>
static std::string ToGroupString(const T& group, const std::string& sep = ",")
{
    std::stringstream ss;
    bool is_first = true;
    for (auto item : group)
    {
        if (is_first)
        {
            is_first = false;
        }
        else
        {
            ss << sep;
        }
        ss << item;
    }
    return ss.str();
}

void stAgency::CopyFrom(const agency_proto::Agency& agency)
{
    this->id = agency.id();
    this->name = agency.name();
    this->encode_key = agency.encode_key();
    this->currency = agency.currency();
    this->country_list.clear();
    for (auto& item : agency.country_list())
    {
        this->country_list.emplace(item);
    }
    this->language_list.clear();
    for (auto& item : agency.language_list())
    {
        this->language_list.emplace(item);
    }
    this->api_url = agency.api_url();
    this->call_url = agency.call_url();
    this->white_ips.clear();
    for (auto& item : agency.white_ips())
    {
        this->white_ips.emplace(item);
    }
    this->state = agency.state();
    this->agent_url.clear();
    for (auto& item : agency.agent_url())
    {
        this->agent_url.emplace_back(item);
    }
    this->gamelist.clear();
    for (auto& item : agency.gamelist())
    {
        this->gamelist.emplace(item);
    }
    this->currency_unit_multi = agency.currency_unit_multi();
}
void stAgency::CopyTo(agency_proto::Agency& agency) const
{
    agency.set_id(this->id);
    agency.set_name(this->name);
    agency.set_encode_key(this->encode_key);
    agency.set_currency(this->currency);
    for (auto& item : this->country_list)
    {
        agency.add_country_list(item);
    }
    for (auto& item : this->language_list)
    {
        agency.add_language_list(item);
    }
    agency.set_api_url(this->api_url);
    agency.set_call_url(this->call_url);
    for (auto& item : this->white_ips)
    {
        agency.add_white_ips(item);
    }
    agency.set_state(this->state);
    for (auto& item : this->agent_url)
    {
        agency.add_agent_url(item);
    }
    for (auto& item : this->gamelist)
    {
        agency.add_gamelist(item);
    }
    agency.set_currency_unit_multi(currency_unit_multi);
}

stAgency& stAgency::operator = (const stAgency& that)
{
    this->id = that.id;
    this->name = that.name;
    this->encode_key = that.encode_key;
    this->currency = that.currency;
    this->country_list = that.country_list;
    this->language_list = that.language_list;
    this->api_url = that.api_url;
    this->call_url = that.call_url;
    this->white_ips = that.white_ips;
    this->state = that.state;
    this->agent_url = that.agent_url;
    this->gamelist = that.gamelist;
    this->currency_unit_multi = that.currency_unit_multi;
    return *this;
}
stAgency& stAgency::operator = (stAgency&& that)
{
    this->id = std::move(that.id);
    this->name = std::move(that.name);
    this->encode_key = std::move(that.encode_key);
    this->currency = std::move(that.currency);
    this->country_list = std::move(that.country_list);
    this->language_list = std::move(that.language_list);
    this->api_url = std::move(that.api_url);
    this->call_url = std::move(that.call_url);
    this->white_ips = std::move(that.white_ips);
    this->state = std::move(that.state);
    this->agent_url = std::move(that.agent_url);
    this->gamelist = std::move(that.gamelist);
    this->currency_unit_multi = std::move(that.currency_unit_multi);
    return *this;
}

std::string stAgency::ToString() const
{
    std::stringstream ss;
    ss << "{" 
        << "id:" << this->id << ","
        << "name:" << this->name << ","
        << "encode_key:" << this->encode_key << ","
        << "currency:" << this->currency << ","
        << "currency_unit_multi:" << this->currency_unit_multi << ","
        << "country_list:" << ToGroupString(this->country_list) << ","
        << "language_list:" << ToGroupString(this->language_list) << ","
        << "api_url:" << this->api_url << ","
        << "call_url:" << this->call_url << ","
        << "white_ips:" << ToGroupString(this->white_ips) << ","
        << "state:" << this->state << ","
        << "agent_url:" << ToGroupString(this->agent_url) << ","
        << "gamelist:" << ToGroupString(this->gamelist) << ","
    << "}";

    return ss.str();
}







